const Router = require('koa-router');
const loginController = require('../controller/common/login');
const uploadController = require('../controller/common/upload');
const collectionsController = require('../controller/common/uploadCollection');
// 路由前缀
const router = new Router({
  prefix: '/api'
});
// const router = new Router()

module.exports = (app) => {
  // 根目录测试
  router.get('/', async (ctx, next) => {
    await ctx.render('index', {
      title: '接口API',
      message: '成功启动后台接口API'
    })
  });

  // 注册与登录校验
  router.post('/loginRegister', loginController.loginRegister);
  router.post('/verifyLogin', loginController.loginCheck);
  // 资料上传
  router.post('/upload', uploadController.upload);
  // 获取上传文件集合
  router.get('/uploadCollections', collectionsController.uploadCollections);

  app
    .use(router.routes())
    .use(router.allowedMethods())
};
